home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 1
/
BUGCD1996_0708.ISO
/
mac
/
Alati
/
GrafiËka pomagala
/
clip2gif 0.7.2.1
/
Scripting clip2gif
/
stat.perl
< prev
Wrap
Text File
|
1995-12-01
|
3KB
|
104 lines
#!/usr/bin/perl
# Copyright 1995, Yves Piguet. All Rights Reserved.
# History:
# 9/95: 1st release
# 12/95: numeric sort instead of ascii sort; cleaned to run under Perl 5 (thanks to Philippe Chartrand)
# file names
$logfile = "MacHTTP.log";
$loghtml = "stat.html";
### processes the log file
open(inFile, $logfile);
for ($i = 0; $i < 24; $i++)
{
$nHour[$i] = 0;
}
while (<inFile>)
{
SWITCH_ext:
{
if (/\.html\b/) { $nExt{"html"}++; last SWITCH_ext; }
if (/\.gif\b/) { $nExt{"gif"}++; last SWITCH_ext; }
if (/\.a?cgi\b/) { $nExt{"cgi"}++; last SWITCH_ext; }
$nExt{"other"}++;
}
/\b(\d\d):\d\d/ && $nHour[$1]++;
$total++;
}
### creates the graphics
$pieData = sprintf("{%.3f,red,%.3f,green,%.3f,blue,%.3f,yellow}", # sum of data should be 360 to have a full pie
360 * $nExt{"html"} / $total,
360 * $nExt{"gif"} / $total,
360 * $nExt{"cgi"} / $total,
360 * $nExt{"other"} / $total);
$pie = "{chart data:" . $pieData . ", chart style:pie, position:{0,0,100,100}}";
$deflabelhtml = 'set html_label to {{rectangle:{110,15,120,25},color:red}, {drawn text:"html", position:{125,25}}}';
$deflabelgif = 'set gif_label to {{rectangle:{110,35,120,45},color:green}, {drawn text:"gif", position:{125,45}}}';
$deflabelcgi = 'set cgi_label to {{rectangle:{110,55,120,65},color:blue}, {drawn text:"cgi", position:{125,65}}}';
$deflabelothr = 'set other_label to {{rectangle:{110,75,120,85},color:yellow}, {drawn text:"other", position:{125,85}}}';
($maxHour) = reverse(sort({$b <=> $a} @nHour)); # rescales data in the range 0-100
for ($i = 0; $i < 24; $i++)
{
$nHour[$i] = int($nHour[$i]*100/$maxHour);
}
$bars = '{chart data:{' . join(',', @nHour) . '}, chart style:bars, thickness:5, position:{0,0,200,100}}';
&MacPerl'DoAppleScript(<<eof); # executes what follows as an AppleScript script
set red to {65535,0,0}
set green to {0,65535,0}
set blue to {0,0,65535}
set yellow to {65535,65535,0}
tell app \"clip2gif\"
$deflabelhtml
$deflabelgif
$deflabelcgi
$deflabelothr
set thePie to $pie
set theDrawingPie to {thePie} & html_label & gif_label & cgi_label & other_label
save {150,100} as GIF drawing theDrawingPie depth 4 colors palette system colors transparency first pixel in file \"extstats.gif\"
set theBars to $bars
save {200,100} as GIF drawing {theBars} depth 1 transparency first pixel in file \"hourlystats.gif\"
end
eof
### writes the html doc
open(outFile, ">" . $loghtml);
print outFile <<eof # writes what follows in the html doc
<html>
<head>
<title>Stats</title>
</head>
<body>
<h1>Stats</h1>
Total number of files: $total <p>
<h2>File Types Transmission Stats</h2>
<img src=extstats.gif><p>
<h2>Hourly Transmission Stats</h2>
<img src=hourlystats.gif><p>
</body>
</html>
eof